package _01SimpleFactoryDesignPattern;

import common.Fruit;

public class Main {
    public static void main(String[] args) {
        //1.if else使用起来灵活性强
//        try {
//            FruitFactory.getFruit("apple").get();
//            FruitFactory.getFruit("banalan").get();
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        } catch (InstantiationException e) {
//            e.printStackTrace();
//        }
        //2.Class.forName()灵活性比较差,而且适用Class.forName（）里面的是个类的全部名称 _01SimpleFactoryDesignPattern+Apple
        try {
            Fruit fruit1 =FruitFactory.getFruit("Apple");
            fruit1.get();
            Fruit fruit2 =FruitFactory.getFruit("Bananan");
            fruit2.get();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
